<template>
    <div>
        房型名称:<input type="text" v-model="infoq.roomname"/>
        备注:<input type="text" v-model="infoq.beizhu"/>
        <input type="button" class="btn btn-success" value="查询" @click="getList"/>
        <h1>房号列表</h1>
        <table class="table table-bordered">
            <input type="button" value="房号增加" class="btn btn-success" @click="ok" />
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>房号</td>
                    <td>排序</td>
                    <td>备注</td>
                    <td>创建时间</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in infoc.list":key="item.id":value="item.id">
                    <td>{{item.roomname}}</td>
                    <td>{{item.roomhao}}</td>
                    <td>{{item.pai}}</td>
                    <td>{{item.beizhu}}</td>
                    <td>{{item.createTime}}</td>
                    <td>{{item.state==1?"启用":"禁用"}}</td>
                    <td>
                        <input type="button" value="删除" class="btn btn-danger" @click="del(item.id)" />
                        <input type="button" value="修改" class="btn btn-info" @click="upd(item.id)" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted,reactive,ref } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';

const route=useRoute();
const router=useRouter();

const ok=()=>{
    router.push('/RoomHAdd');
}

//取数据
const infoq:any=reactive({
    pageindex:1,
    pagesize:3,
    roomname:'',
    beizhu:''
})
//传数据
const infoc:any=reactive({
    list:[],
    totacount:0,
    totapage:0
})

//钩子函数
onMounted(()=>{
    getList();
})
//显示
const getList=()=>{
    axios({
        url:'/api/RoomH/GetList',
        method:'get',
        params:infoq
    })
    .then(res=>{
        console.log(res);
        infoc.list=res.data.list;
        infoc.totacount=res.data.totacount;
        infoc.totapage=res.data.totapage;
    })
    .catch(err=>{
        console.log(err);
    })
}
//删除
const del=(id:any)=>{
   var d=confirm('确定要删除吗?');
     if(d){
            axios({
            url:'/api/RoomH/Del',
            method:'delete',
            params:{
                id:id
            }
        })
        .then(res=>{
            console.log(res);
            if(res.data>0){
                alert('删除成功!');
                getList();
            }
            else{
                alert('删除失败!');
            }
        })
     }
}

const upd=(xid:any)=>{
    router.push({
        path:'/RoomHXiu',
        query:{
            id:xid
        }
    })
}


</script>